{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "# Use CASIA-SURF training dataset and our private dataset for training"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pathlib import Path  #从pathlib中导入Path\n",
    "import os\n",
    "data_dir = os.getcwd() + '/our_filelist'\n",
    "txt_dir=[i for i in list(Path(data_dir).glob(\"**/2*.txt\")) ]# \n",
    "\n",
    "str1 = '/home/zp/disk1T/CASIASURF/data'\n",
    "str2 = os.getcwd()\n",
    "str3 = '/home/zp/disk1T/TSNet-LW/data'\n",
    "\n",
    "for i in range(len(txt_dir)):\n",
    "    s = str(txt_dir[i]).replace('[','').replace(']','')#去除[],这两行按数据不同，可以选择\n",
    "    s2 = s.replace(\"'\",'').replace('our_filelist','')\n",
    "    fp = open(s2,'w')\n",
    "    with open(s,'r') as f:\n",
    "        lines = f.read().splitlines()\n",
    "    for i in lines:\n",
    "        i = i.replace(str1,str2)\n",
    "        i = i.replace(str3,str2)\n",
    "        fp.write( i + '\\n')\n",
    "    fp.close()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Use CASIA-SURF Val data for val"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import fileinput\n",
    "rgb = open('./rgb_val.txt','a')\n",
    "depth = open('./depth_val.txt','a')\n",
    "ir = open('./ir_val.txt','a')\n",
    "label = open('./label_val.txt','a')\n",
    "pwd = os.getcwd() +'/'# the val data path \n",
    "for line in fileinput.input(\"val_label.txt\"):\n",
    "    list = line.split(' ')\n",
    "    rgb.write(pwd +list[0]+'\\n')\n",
    "    depth.write(pwd +list[1]+'\\n')\n",
    "    ir.write(pwd +list[2]+'\\n')\n",
    "    label.write(list[3])\n",
    "rgb.close()\n",
    "depth.close()\n",
    "ir.close()\n",
    "label.close()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
